package it.polimi.swKnights.SWIMv2.servlets.registration;

import it.polimi.swKnights.SWIMv2.ejb.personalData.UserFinderRemote;
import it.polimi.swKnights.SWIMv2.servlets.SwimServlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AjaxRegistrationController
 */
public class AjaxRegistrationController extends SwimServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		PrintWriter out = response.getWriter();
		String user = request.getParameter("typed");

		UserFinderRemote userFinderBean = this.lookUp(UserFinderRemote.class);

		
		if (userFinderBean.existingUserName(user))
		{
			
			out.println("<span class=\"red\">User Already Exist</span>");
			
			
		}
		else if (user.equals(""))
		{
			out.println("");
		}
		else
		{
		
			out.println("<span class=\"green\">User Available</span>");
		}

	}

}
